package com.threadmethod.volatiled;

/**
 * @PackageName:com.threadmethod.volatiled
 * @ClassName:Test03
 * @Description:
 * @Author: zhangxiaoyu
 * @date 2020/12/10 16:05
 */
public class Test03 {

    public static void main(String[] args){
         //创建10个现线程
        for (int i=0;i<100;i++){
            new Mythread().start();
        }
    }


    static  class  Mythread extends  Thread{

        //volatile 仅仅表示所用线程从内存中读取变量的值
        public static  int count;

        public synchronized static void addCount(){
            for (int i = 0;i<1000;i++){
                count++;
            }
            System.out.println(Thread.currentThread().getName()+"count="+count);

        }

        @Override
        public void run() {
            addCount();
        }
    }
}
